package com.boot.modules.auth.service.impl;

import com.boot.common.entity.CustomUserDetails;
import com.boot.modules.auth.service.CustomUserDetailsService;
import com.boot.system.entity.SysUser;
import com.boot.system.service.UserCacheService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service("customUserDetailsService")
public class CustomUserDetailsServiceImpl implements CustomUserDetailsService {

    private final UserCacheService userCacheService;

    @Override
    public UserDetails loadUserByUsername(String username) {
        //从缓存中获取用户信息
        SysUser user = userCacheService.getCacheUser(username);
        if (user == null) {
            return null;
        }
        return new CustomUserDetails(user);
    }

}
